<?

class Phlare extends PHLARE_Model
{
	public $model_folder = '';
	
    public function __construct()
    {
        parent::__construct();
		
		// Assign the model folder
		$this->model_folder = APPPATH . 'models/';
    } // end __construct
    
    /**
     * get_model_list:
     * Return an array who's key is the class and the value is the model with
     * subdirectory, a string that can be directly used to load the model.
     * 
     * @return Array List of model files
     */
    public function get_model_list()
	{
		
		$models = array();
		
		// Use iterator to loop over model list and return file names
		$contents = new RecursiveDirectoryIterator($this->model_folder);
		foreach(new RecursiveIteratorIterator($contents) as $file) {
			if(substr($file->getFilename(), -4) === '.php')
			{
				$file_path = $file->getFileInfo();
				
				// Determine the model
				$model = str_replace($this->model_folder, '', $file_path);
				
				// Determine the class/model
				$file_parts = explode(DIRECTORY_SEPARATOR, $model); // Could be in a sub-dir
				$file_name = $file_parts[count($file_parts) - 1];
				// Strip the .php extension off
				$class = ucfirst(substr_replace($file_name, '', -4, 4));
				$model = substr_replace($model, '', -4, 4);
				
				$models[$class] = $model;
			}
		}
		
		return $models;
		
	} // end get_model_list
	
} // end Phlare